package leetcode;


import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * 杨辉三角 II
 */
public class LeetCode119 {
    public List<Integer> getRow(int rowIndex) {
        int[] numbs = new int[rowIndex + 1];
        for (int i = 0; i < rowIndex + 1; i++) {
            numbs[0] = 1;
            numbs[i] = 1;
            int prev = numbs[0];
            for (int j = 1; j < i; j++) {
                int temp = numbs[j];
                numbs[j] = prev + numbs[j];
                prev = temp;
            }
        }
        return toList(numbs);
    }

    public List<Integer> toList(int[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        return list;
    }

    public static void main(String[] args) {
        LeetCode119 leetCode119 = new LeetCode119();
        System.out.println(JSON.toJSONString(leetCode119.getRow(0)));
    }
}